package com.fps.web.controller.mobile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fps.web.model.Basememory;
import com.fps.web.service.BasememoryService;
import com.fpswork.Helper.HttpResult;
import com.fpswork.core.exception.exception.BusinessException;
import com.fpswork.util.ShortUrlGenerator;


@Controller
@RequestMapping("/m_app")
public class AppController {
    @Autowired
    BasememoryService basememoryService;
		/*
	    *实例
	    */
	    @RequestMapping(value = "/eg")
	    public  @ResponseBody HttpResult eg(Model model,String date,HttpServletResponse response) { 
	    	try{	
	    		response.setHeader("Access-Control-Allow-Origin", "*"); 
	    		System.out.println("==========================eg");
	    		
				return HttpResult.success(model);
			}catch(Exception e){
				return HttpResult.build("error", e.getMessage());
			}
	    	
	    }
/*	    @RequestMapping(value = "/shorten", method = RequestMethod.POST)
	    public @ResponseBody Map<String, String> basememoryAddSubmit(String url) throws Exception{
	    	String[] shortUrl= ShortUrlGenerator.shortUrl(url);
	    	Basememory basememory = new Basememory();
	    	basememory.setType(url);
    		basememory.setContent(shortUrl[0]);
    		basememoryService.addBasememory(basememory);
	    	Map<String, String> map = new HashMap<String, String>();
	    	map.put("url", shortUrl[0]+".html");
	        return map;
	    }
	    	
		    *实例
		    	 
		    @RequestMapping(value = "/{url}")
		    public void url(Model model,@PathVariable String url,HttpServletResponse res,HttpServletRequest req) { 
		    	try {
					Basememory Basememory =basememoryService.queryBasememoryByID(url);
					try {
						res.sendRedirect(Basememory.getType());
					} catch (IOException e) {
						e.printStackTrace();
					}
				} catch (BusinessException e1) {
					e1.printStackTrace();
				}
		    
		    }*/
		    
	
	
}
